<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1>购买页面</h1>
  <button id="btn">购买</button>
  <script src="./jquery-3.4.1.min.js"></script>
  <script>
    $("#btn").click(function () {
      $.ajax({
        url: "http://127.0.0.1:3000/users/buy",
        type: "post",
        data: {
          token: localStorage.token
        },
        success: function (res) {
          console.log(res)
          if (res.success) {
            alert("购买成功")
          }
          if (res.err) {
            alert("请先登录")
            location.href = "./login.html"
          }
        }
      })
    })



  </script>
</body>

</html>